package com.nervenets.web.controller.bank;

import com.nervenets.web.hibernate.domain.AccountHold;
import com.nervenets.web.redis.GlobalService;
import com.nervenets.web.redis.domain.BuildingStored;
import lombok.Data;

import java.io.Serializable;

@Data
public class AccountHoldDto implements Serializable {
    private long id;
    private String userName;
    private String userAvatar;
    private long userId;
    private long buildingId;
    private String buildingName;
    private String buildingCover;
    private int money;

    public AccountHoldDto(AccountHold hold, GlobalService globalService) {
        this.id = hold.getId();
        this.userName = hold.getUser().getName();
        this.userAvatar = hold.getUser().getAvatar();
        this.userId = hold.getUser().getId();
        this.buildingId = hold.getBuildingId();
        if (this.buildingId > 0) {
            final BuildingStored building = globalService.getBuilding(this.buildingId);
            if (null != building) {
                this.buildingName = building.getName();
                this.buildingCover = building.getCover();
            }
        }
        this.money = hold.getMoney();
    }
}
